/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.composite.editpart;

import org.eclipse.uml2.uml.Connector;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.editpart.LinkNameDisplayEditPart;
import com.cea.papyrus.core.figures.StringFigure;
import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

/**
 * Controller that manages a Connector name label
 */
public class ConnectorNameEditPart extends LinkNameDisplayEditPart{
	
	/**
	 * Creates a new ConnectorNameEditPart
	 * @param graphnode the graph node displaying the name of a connector
	 * @param modelManager the model manager associated to the editor
	 */
	public ConnectorNameEditPart(GraphNode graphnode, ModelManager modelManager) {
		super(graphnode,modelManager);
	}

	/**
	 * Creates a new ConnectorNameEditPart with a specified element
	 * @param element the element 
	 * @param graphnode the graphnode displaying the name of a connector
	 * @param modelManager the model manager associated to the editor
	 * @param graphnode 
	 */
	public ConnectorNameEditPart(GraphNode graphnode,org.eclipse.uml2.uml.Element element,ModelManager modelManager) {
		super(graphnode,modelManager);
		Debug.debug(this, "create NameDisplayEditPart("+ element+")", channel);
		this.element = element;
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.common.editpart.LinkNameDisplayEditPart#createFigure()
	 */
	@Override
	protected StringFigure createFigure() {
		if(element instanceof Connector) {
			String type=" : ";
			if(((Connector)element).getType()!=null) {
				type=type+((Connector)element).getType().getName();
			}
			else{type="";}
			return new StringFigure(((Connector)element).getName()+type);} 
		else {
			return new StringFigure("");
		}
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.common.editpart.LinkNameDisplayEditPart#refreshVisuals()
	 */
	@Override
	protected void refreshVisuals() {
		StringFigure f = (StringFigure) getFigure();
//		Dimension size = getGraphNode().getSize();
//		Point p = getGraphNode().getPosition();
//		Rectangle r = new Rectangle(p ,size);
		if(element instanceof Connector){
			String type=" : ";
			if(((Connector)element).getType()!=null) {
				type=type+((Connector)element).getType().getName();
			}
			else{
				//TODO should be <Undefined> ?!
				type="";
			}
			f.setText(((Connector)element).getName()+type);
		}
		f.setVisible(this.isVisible());	
	}
}
